package openai

import (
	"encoding/json"

	"github.com/EDDYCJY/go-gin-example/middleware/jwt"
	"github.com/EDDYCJY/go-gin-example/pkg/app"
	"github.com/EDDYCJY/go-gin-example/pkg/openai/sdk"
	"github.com/gin-gonic/gin"
)

// 云服务器路由注册
func RouterRegister(r *gin.Engine) {
	groupVersion := r.Group("/v1/openai")
	{
		ecsGrouop := groupVersion.Group("/ecs")
		{
			ecsGrouop.GET("/test", func(c *gin.Context) {
				appG := app.Gin{C: c}
				sdk.SetUp()
				signer := sdk.OpenAIInstance
				signer.AddParam("Action", "DescribeImages")
				signer.AddParam("RegionId", "Southwest08")
				content, err := signer.Request()
				if err != nil {
					appG.ResponseError(1, err.Error())
				}
				isFall := sdk.ValidateJSON(string(content), &sdk.FallbackData{})
				if isFall {
					appG.ResponseError(1, "网络错误")
				}
				json.Unmarshal(content, &sdk.Response)
				appG.ResponseSuccess(sdk.Response)
			})

			ecsGrouop.GET("/DescribeInstancesInfo", jwt.JWT(), DescribeInstancesinfo)
			ecsGrouop.GET("/CreateInstance", jwt.JWT(), CreateInstance)
			ecsGrouop.GET("/DescribeInstanceTypes", DescribeGPUInstances)
			ecsGrouop.GET("/ModifyInstanceAttribute", ModifyInstanceAttribute)
			ecsGrouop.GET("/DescribeInstanceVncUrl", DescribeInstanceVncUrl)
		}
	}
}
